<%@ Page Title="Applications &raquo; ResourceBlender" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Applications.aspx.cs" Inherits="Applications" EnableEventValidation="false" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>

<asp:Content ID="contentHead" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

<asp:Content ID="contentMain" ContentPlaceHolderID="cntMain" Runat="Server">
    <form id="frmApplications" runat="server">
        <asp:SqlDataSource ID="dsMain" runat="server"
             ConnectionString="<%$ ConnectionStrings:Default %>"
             ProviderName="<%$ ConnectionStrings:Default.ProviderName %>"
             SelectCommand="SELECT name, id, type, displayname FROM applications"></asp:SqlDataSource>
        <div style="width: 90%; margin: 0 auto;">
            <asp:MultiView ID="mltMain" runat="server" ActiveViewIndex="1">
                <asp:View ID="viwManageApplications" runat="server">
                    <h1><asp:Label ID="lblManageApplications" runat="server" Text="Manage Applications"></asp:Label></h1>
                    <asp:GridView ID="grdApplications" runat="server" AllowPaging="True" 
                        AllowSorting="True" AutoGenerateColumns="False" CssClass="nicetable" 
                        DataSourceID="dsMain" OnRowCommand="grdApplications_RowCommand" Width="100%">
                        <PagerSettings PageButtonCount="7" />
                        <Columns>
                            <asp:BoundField DataField="displayname" HeaderText="Application" 
                                SortExpression="displayname" />
                            <asp:TemplateField HeaderText="Type">
                                <ItemTemplate>
                                    <asp:Label ID="applicationType" runat="server" 
                                        Text='<%# EnumBinder.EnumHelper.GetDescription((Constants.ResourceType)Enum.Parse(typeof(Constants.ResourceType), Eval("type").ToString())) %>'
                                        CssClass='<%# Enum.Parse(typeof(Constants.ResourceType), Eval("type").ToString()) %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField ItemStyle-CssClass="buttoncell" HeaderText="Edit">
                                <ItemTemplate>
                                    <asp:ImageButton ID="btnEdit" runat="server" 
                                        AlternateText='<%# "Edit " + Eval("displayname") %>' 
                                        CommandArgument='<%# Eval("id") %>' CommandName="edit" 
                                        ImageUrl="~/images/edit.png" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField ItemStyle-CssClass="buttoncell" HeaderText="Delete">
                                <ItemTemplate>
                                    <asp:ImageButton ID="btnDelete" runat="server" 
                                        AlternateText='<%# "Delete " + Eval("displayname") %>' 
                                        CommandArgument='<%# Eval("id") %>' CommandName="confirmdelete" 
                                        ImageUrl="~/images/delete.png" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <HeaderStyle CssClass="excelHead" />
                        <AlternatingRowStyle CssClass="alt" />
                        <EmptyDataTemplate>
                            <p>No applications have been added.</p>
                        </EmptyDataTemplate>
                    </asp:GridView>
                    <asp:LinkButton ID="lnkAddApplication" runat="server" CssClass="lnkAdd" 
                        onclick="lnkAddApplication_Click">Add Application</asp:LinkButton>
                </asp:View>
                <asp:View ID="pnlAddApplication" runat="server">
                    <div class="niceform">
                        <h1><asp:Label ID="lblEditApplications" runat="server" Text="Add Application"></asp:Label></h1>
                        <fieldset>
                            <legend>Application Options</legend>
                            <div class="formrow block">
                                <asp:Label ID="lblAppName" runat="server" AssociatedControlID="txtAppName" 
                                    Text="Application Name"></asp:Label>
                                <asp:TextBox ID="txtAppName" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="vldAppName" runat="server" 
                                    ControlToValidate="txtAppName" Display="Dynamic" 
                                    ErrorMessage="You must enter the application name" 
                                    CssClass="validationerror"></asp:RequiredFieldValidator>
                            </div>
                            <div class="formrow block">
                                <asp:Label ID="lblDisplayName" runat="server" AssociatedControlID="txtDisplayName" 
                                    Text="Display Name"></asp:Label>
                                <asp:TextBox ID="txtDisplayName" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="vldDisplayName" runat="server" 
                                    ControlToValidate="txtDisplayName" Display="Dynamic" 
                                    ErrorMessage="You must enter a display name" CssClass="validationerror"></asp:RequiredFieldValidator>
                            </div>
                            <div class="formrow block">
                                <asp:Label ID="lblAppType" runat="server" Text="Type" 
                                    AssociatedControlID="cboAppType"></asp:Label>
                                <asp:DropDownList ID="cboAppType" runat="server">
                                </asp:DropDownList>
                            </div>
                        </fieldset>
                        <fieldset>
                            <legend>Languages</legend>
                            <div class="formrow block">
                                <div class="formcol">
                                    <asp:Label ID="lblLanguages" runat="server"
                                        AssociatedControlID="lstSelectedLangs" Text="Selected Languages"></asp:Label>
                                    <br />
                                    <asp:ListBox ID="lstSelectedLangs" runat="server" Width="20em" Rows="10" 
                                        CausesValidation="True" SelectionMode="Multiple" 
                                        ValidationGroup="vldLanguages"></asp:ListBox>
                                </div>
                                <div class="formcol" style="margin-top: 7em;">
                                    <asp:Button ID="btnAddLang" runat="server" Text="&lt;&lt;" 
                                        EnableViewState="False" CssClass="block" onclick="btnAddLang_Click" 
                                        onclientclick="return addLanguages()" />
                                    <asp:Button ID="btnRemoveLang" runat="server" Text="&gt;&gt;" 
                                        EnableViewState="False" CssClass="block" onclick="btnRemoveLang_Click" 
                                        onclientclick="return removeLanguages()" />
                                </div>
                                <div class="formcol">
                                    <asp:Label ID="lblAvailableLanguages" runat="server" 
                                        AssociatedControlID="lstAvailableLangs" Text="Available Languages"></asp:Label>
                                    <br />
                                    <asp:ListBox ID="lstAvailableLangs" runat="server" Width="20em" Rows="10" 
                                        SelectionMode="Multiple"></asp:ListBox>
                                </div>
                                <div class="clear"></div>
                                <asp:CustomValidator ID="vldHasLanguages" runat="server" 
                                ControlToValidate="lstSelectedLangs" 
                                ErrorMessage="At least one language must be selected" 
                                onservervalidate="validateHasLanguages" ValidateEmptyText="True" 
                                    ValidationGroup="vldLanguages"></asp:CustomValidator>
                                <br />
                            </div>
                            <br />
                            <div class="formrow block">
                            <asp:Label ID="lblDefaultLanguage" runat="server" Text="Default Language" CssClass="block"
                                AssociatedControlID="cboDefaultLanguage"></asp:Label>
                            <asp:DropDownList ID="cboDefaultLanguage" runat="server">
                            </asp:DropDownList>
                        </div>
                        </fieldset>
                        <fieldset>
                            <legend>Bundles</legend>
                            <div class="formrow block">
                                <div class="formcol">
                                    <asp:Label ID="lblBundles" runat="server" 
                                        AssociatedControlID="lstBundles" Text="Included Bundles"></asp:Label>
                                    <br />
                                    <asp:ListBox ID="lstBundles" runat="server" Width="20em" Rows="10" 
                                        CausesValidation="True" SelectionMode="Multiple"></asp:ListBox>
                                    <br />
                                    <asp:Button ID="btnRemoveBundle" runat="server" CommandName="bundleremove" 
                                        EnableViewState="False" Text="Remove Selected Bundle" 
                                        CausesValidation="False" onclick="btnRemoveBundle_Click" 
                                        onclientclick="return removeBundles()" />
                                </div>
                                <div class="formcol">
                                    <asp:Label ID="lblNewBundle" runat="server" 
                                        AssociatedControlID="txtNewBundle" Text="New Bundle"></asp:Label>
                                    <br />
                                    <asp:TextBox ID="txtNewBundle" runat="server"></asp:TextBox>
                                    <br />
                                    <asp:Button ID="btnAddBundle" runat="server" CommandName="bundleadd" 
                                        CssClass="uniformbutton" EnableViewState="False" Text="Add Bundle" 
                                        CausesValidation="False" onclick="btnAddBundle_Click" 
                                        onclientclick="return addBundle()" />
                                </div>
                            </div>
                        </fieldset>
                        
                        <div class="formrow block">
                            <asp:Button ID="btnSave" runat="server" Text="Save" CssClass="uniformbutton" 
                                onclick="btnSave_Click" onclientclick="checkAllLanguages()" />
                        </div>
                        <asp:HiddenField ID="hidApplicationId" runat="server" Value="add">  
                        </asp:HiddenField>
                    </div>
                </asp:View>
                <asp:View ID="pnlDeleteApplication" runat="server">
                    <div class="niceform confirmation">
                        <h1><asp:Label ID="lblConfirmDeletionHeading" runat="server" Text="Confirm Deletion" 
                                EnableViewState="False"></asp:Label></h1>
                        <asp:Label ID="lblConfirmDelete" runat="server" 
                            Text="formatted text"></asp:Label>
                        <br />
                        <asp:Button ID="btnOk" runat="server" CommandName="confirmdelete" 
                            CssClass="uniformbutton" EnableViewState="False" onclick="btnOk_Click" 
                            Text="OK" />
                        <asp:Button ID="btnCancelDelete" runat="server" CommandName="canceldelete" 
                            CssClass="uniformbutton" EnableViewState="False" Text="Cancel" 
                            onclick="btnCancelDelete_Click" />
                        <asp:HiddenField ID="hidApplicationIdDelete" runat="server" Value="delete">  
                        </asp:HiddenField>
                    </div>
                </asp:View>
            </asp:MultiView>
        </div>
    </form>
</asp:Content>